package com.axx.android.moments;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.axx.android.R;
import com.axx.android.base.BaseActivity;
import com.axx.android.utils.ImageLoader;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.previewlibrary.PhotoActivity;
import com.previewlibrary.ThumbViewInfo;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ShowMeContentActivity extends BaseActivity {

    @Bind(R.id.btn_back)
    Button btnBack;
    @Bind(R.id.iv_image)
    ImageView ivImage;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.rv_image)
    RecyclerView rvImage;
    @Bind(R.id.tv_time)
    TextView tvTime;
    @Bind(R.id.iv_up)
    ImageView ivUp;
    @Bind(R.id.tv_up_cnt)
    TextView tvUpCnt;
    @Bind(R.id.activity_subject_comment)
    LinearLayout activitySubjectComment;
    @Bind(R.id.tv_location)
    TextView tvLocation;
    @Bind(R.id.layout_location)
    LinearLayout layoutLocation;


    @Override
    public int getLayoutId() {
        return R.layout.activity_show_me_content;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        ShowMeModel.ShowMeListBean showMeModel = (ShowMeModel.ShowMeListBean) getIntent().getSerializableExtra("model");
        tvContent.setText(showMeModel.getText());
        ImageLoader.loadRoundImage(getIntent().getStringExtra("header"), ivImage, this);

        if (showMeModel.getPic() != null && showMeModel.getPic().size() != 0) {
            List<ImageModel> list = new ArrayList<>();
            final ArrayList<ThumbViewInfo> thumbViewInfos = new ArrayList<>();
            for (String str : showMeModel.getPic()) {
                ImageModel imageModel = new ImageModel();
                imageModel.setAdd(false);
                imageModel.setCanDel(false);
                imageModel.setUrl(str);
                list.add(imageModel);

                ThumbViewInfo thumbViewInfo = new ThumbViewInfo(str);
                thumbViewInfos.add(thumbViewInfo);
            }

            ImageAdapter imageAdapter = new ImageAdapter(R.layout.view_item_image, list);
            rvImage.setLayoutManager(new GridLayoutManager(this, 4));
            rvImage.setAdapter(imageAdapter);

            imageAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    PhotoActivity.startActivity(ShowMeContentActivity.this, thumbViewInfos, position);
                }
            });
        }

        if (!showMeModel.getPlace().equals("不使用地址")) {
            tvLocation.setText(showMeModel.getPlace());
            layoutLocation.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
